package Sagittarius.Manager
{
	import com.pblabs.engine.debug.Logger;
	
	import VO.EnemyVO;
	
	/**************************************************************************
	 * ...
	 * @author Aqua
	 *************************************************************************/
	public class EnemyManager
	{
		//------------------- Singleton -------------------//
		/**************************************************************************
		 * function					instance getter
		 * description				a private function used to enforce singlton
		 * @return	EnemyManager	singleton instance of this class
		 *************************************************************************/
		public static function get instance():EnemyManager
		{
			if(null == _instance)
			{
				_instance = new EnemyManager(singleton);
			}
		
			return _instance;
		}
		
		/**************************************************************************
		 * function				singleton
		 * description			a private function used to enforce singlton
		 *************************************************************************/
		private static function singleton():void
		{
			
		}
		//------------------- End Of Singleton -------------------//		
		
		
		//------------------- Constructor -------------------//
		/**************************************************************************
		 * function				EnemyManager
		 * description			constructor
		 * @param	s			a private function used to enforce singlton
		 *************************************************************************/
		public function EnemyManager(s:Function = null):void
		{
			if (singleton != s)
			{
				throw new Error("This is a singleton class!");
			}
		}
		//------------------- End Of Constructor -------------------//
		
		
		//------------------- Interface -------------------//
		/**************************************************************************
		 * function				addType
		 * description			add a new enemy type
		 * @param	id			an unique id of this type
		 * @param	resourceId	the id of this type's resource
		 * @param	radius		radius of the circle for crash-test
		 * @param	life		life of this type of enemy, default to be 1 (die on any attack)
		 * @param	score		score that can be gained when player shoots down this enemy
		 *************************************************************************/
		public function addType(id			:String,
								resourceId	:String,
								radius		:Number,
								life		:int = 1,
								score		:int = 0):void
		{
			if (ObjectManager.instance.hasObj(id))
			{
				Logger.print(this, "Enemy type [" + id + "] already exists!");
				return;
			}
			
			if (! ResourceManager.instance.hasResource(resourceId))
			{
				Logger.print(this, "Resource [" + resourceId + "] doesn't exist!");
				return;
			}
			
			var enemyVO:EnemyVO;
			
			enemyVO				= new EnemyVO();
			enemyVO.id			= id;
			enemyVO.resourceId	= resourceId;
			enemyVO.radius		= radius;
			enemyVO.life		= life;
			_enemyTypes[id]		= enemyVO;
			
			ObjectManager.instance.addObj(id, enemyVO);
		}
		//------------------- End Of Interface -------------------//
		
		
		//------------------- Private Functions -------------------//
		/**************************************************************************
		 * function				initialize
		 * description			initialize data
		 *************************************************************************/
		private function initialize():void
		{
			_enemyTypes = {};
		}
		//------------------- End Of Private Functions -------------------//
		
		
		private static var _instance:EnemyManager;
		
		private var _enemyTypes		:Object;
	}
	
}